package com.samphanie.security.validation.properties;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;

import javax.validation.constraints.Min;
import java.util.ArrayList;
import java.util.List;

/**
 * @author ZSY
 * @email 1451691457@qq.com
 */
@Getter
@Setter
@Validated
@Component
@ConfigurationProperties(prefix = "auiu.validate")
public class ValidateProperties {

    // 谷歌验证码
    private KaptchaProperties kaptcha = new KaptchaProperties();
    // 短信验证码
    private SmsCodeProperties sms = new SmsCodeProperties();

    @Getter
    @Setter
    public static class KaptchaProperties {
        /**
         * 宽度
         */
        private Integer width = 200;
        /**
         * 高度
         */
        private Integer height = 50;
        /**
         * 过期时间 s
         */
        @Min(60L)
        private long expireIn = 60;
        /**
         * 需要验证的url
         */
        private List<String> urls = new ArrayList<>();
        /**
         * 内容
         */
        @NestedConfigurationProperty
        private Content content = new Content();
        /**
         * 背景色
         */
        @NestedConfigurationProperty
        private BackgroundColor backgroundColor = new BackgroundColor();
        /**
         * 字体
         */
        @NestedConfigurationProperty
        private Font font = new Font();
        /**
         * 边框
         */
        @NestedConfigurationProperty
        private Border border = new Border();

        @Data
        public static class BackgroundColor {
            /**
             * 开始渐变色
             */
            private String from = "lightGray";
            /**
             * 结束渐变色
             */
            private String to = "white";
        }

        @Getter
        @Setter
        public static class Content {
            /**
             * 内容源
             */
            private String source = "abcdefghjklmnopqrstuvwxyz23456789";
            /**
             * 内容长度
             */
            @Min(2)
            private Integer length = 4;
            /**
             * 内容间隔
             */
            private Integer space = 2;
        }

        @Getter
        @Setter
        public static class Border {
            /**
             * 是否开启
             */
            private Boolean enabled = true;
            /**
             * 颜色
             */
            private String color = "black";
            /**
             * 厚度
             */
            private Integer thickness = 1;
        }

        @Getter
        @Setter
        public static class Font {
            /**
             * 名称
             */
            private String name = "Arial";
            /**
             * 颜色
             */
            private String color = "black";
            /**
             * 大小
             */
            private Integer size = 40;
        }
    }

    @Getter
    @Setter
    public static class SmsCodeProperties {
        @Min(2)
        private Integer length = 6;
        @Min(60L)
        private long expireIn = 60;
        private List<String> urls = new ArrayList<>();
    }
}
